package com.jsaas.sys.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Duang;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jsaas.controller.base.BaseController;
import com.jsaas.model.Permission;
import com.jsaas.sys.service.PermissionService;

/**   
* @Title: PermissionController.java 
* @Package com.jsaas.sys.controller 
* @Description: TODO(权限管理) 
* @author tuozq 
* @date 2017年12月15日 上午11:12:38 
* @version V1.0   
*/
public class PermissionController extends BaseController {
	
	public void index(){
		render("listPermission.html");
	}
	
	public void edit(){
		String id = getPara("id");
		if(StrKit.notBlank(id)){
			setAttr("model", Permission.dao.findById(id));
		}else{
			setAttr("model", new Permission());
		}
		render("editPermission.html");
	}
	
	@Before(Tx.class)
	public void save(){
		Permission model = getModel(Permission.class, "model");
		Ret ret = Duang.duang(PermissionService.class).save(model);
		renderJson(ret);
	}
	
	public void query(){
		Page<Permission> pagedata = Permission.dao.pageinit(initPageParams(getRequest(), "permission.findPermission"));
		renderJson(pagedata);
	}
	
	@Before(Tx.class)
	public void generator(){
		Ret ret = Duang.duang(PermissionService.class).generatorAtionKey();
		renderJson(ret);
	}
	
	@Before(Tx.class)
	public void delete(){
		String id = getPara("id");
		Ret ret = Duang.duang(PermissionService.class).delete(id);
		renderJson(ret);
	}
	
}
